package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-01-11
 * Time:23:52
 */
public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            while (true){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        //在调用start之前获取的状态，此时就是new状态
        System.out.println(t.getState());
        t.start();
        for (int i = 0; i < 5; i++) {
            System.out.println(t.getState());
            Thread.sleep(1000);
        }
        t.join();
        //在线程执行结束之后，获取线程的状态，此时就是TERMINATED状态
        System.out.println(t.getState());
    }
}
